<?
include("common/header.html");
include("../_made/le.cfg.php");
include("common/page.php");
include("common/left.html");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
if(!$_SESSION['memberID']){}
$pid=explode("|",$_REQUEST["pid"]);
$cN=$c=$name=$class=$son=$fp=$p_name=array();
$sel="select pid,title,landid from uu_jq_ticket where pid in (".implode(",",$pid).")";
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
	$lid=$row['landid'];
	$p_name[$row['pid']]=$row["title"];
	$fp[$row['pid']]=$s->get_Dynamic_Price_Merge($row['pid'],date("Y-m-d"),2)/100;
}
$sel="select title,apply_did from uu_land where id=".$lid." limit 1";
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$ltitle=$GLOBALS['le']->f("title");
if($GLOBALS['le']->f("apply_did")!=$_SESSION['memberID']){
	exit("<script>window.location='home.html'</script>");
}
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:7;
$sel="select s.dtype,s.dtitle,dname,m.account,m.id from pft_product_sale_list s left join pft_member m on m.id=s.fid where aid=".$_SESSION['memberID']." and m.status in (0,3) and s.status=0";//." limit ".($currentPage-1)*$pageSize.",".$pageSize;
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
	if((int)$row['dtype']!=0){$class[$row['dtype']][]=$row;}
	else{$son[]=$row;}
	if(!in_array($row['dtype'],$cN)){$cN[$row['dtype']]=$row['dtitle'];}
	$name[$row['id']]=$row['account']."-".$row['dname'];
}
foreach($class as $k=>$v){
	$_t=array();
	foreach($v as $r){
		$_t[]=$r['id'];
	}
	$c[$k]=implode(",",$_t);
}
?>
<style type="text/css">
button{cursor: pointer;}
table{width:100%; line-height:23px; margin:10px 0; border:1px solid #d5dce2;}
th,td{ text-align:center; border-color:#d5dce2; line-height:30px;}
th{background:#f2f9ff;}
.clearfix:after{ content:""; display:block; clear:both; visibility:hidden;}
* .clearfix{ zoom:1;}
.wrap{width:80%;float:right;}
.ctitle{height:23px; width:120px;}
.pri_inp{width:45px;height:22px;text-align:center;vertical-align:-4px\9;}
.info{ border-color:#CCC; margin-top:0;}
.info th{background:#F4F4F4; }

#add{background:#FFF; left:50%; margin-left:-20%; position:absolute; top:217px; width:50%; padding:10px; padding-bottom:40px; border:1px solid #D5DCE2; z-index:100;}
#add p{height:27px;}
#add .btn{position: absolute;left: 50%;margin-left: -45px;}
.addcp {background: url("../images/btn23_two1.png") no-repeat scroll left top rgba(0, 0, 0, 0);display: inline-block;height: 23px;padding-left: 8px;text-decoration: none;}
.addcp span {background: url("../images/btn23_two1.png") no-repeat scroll right top rgba(0, 0, 0, 0);color: #FFFFFF;display: inline-block;font-size: 12px;font-weight: bold;height: 23px;line-height: 23px;padding-right: 8px;}
.close{ border: 1px solid #2A98DA;color:#2A98DA;font-weight: bold;line-height:17px;font-size: 18px;display: inline-block;height: 20px;position: absolute;right: 10px;text-align: center;width: 20px;cursor: pointer;}

.ok{display:block;line-height: 22px;margin: 0 auto;width: 100px;}

.C{}
.C th{width:80%;text-align:left;background:#f2f9ff; line-height:30px; padding-left:2%; }
.list{text-align:left; padding:1%; line-height:25px;}
.list span{ margin-right:10px; display:inline-block;}
.C_r{text-align:center;}
.C_r span{display:inline-block; margin:5px 0;}
.addFx{float:right; margin-right:30px;}
.open{background:#FFF; border:1px solid #000000; display:inline-block; height:15px; line-height:13px; text-align:center; width:15px; margin-right:15px; cursor:pointer;}

.hidden{}
.hidden th{width:40%;}
.hidden .C_r span{display:inline;}
.hidden .list{display:none;}

#mod{display:none;}
</style>
<script type="text/javascript">
var c=<?=json_encode($c)?>;
var n=<?=json_encode($name)?>;
var dtype=0;
function add(d){
	dtype=d;
	$('#add').show();
	$('#mask').show();
	var tr=$("#add table tbody tr");
	tr.each(function(i,e){
		if(i!=0)$(e).remove();
	})
	var id=$.ajax({url:"call/release.php",data:{type:"getID",dtype:d},async:false}).responseText;
	id=id?id.split(","):[];
	var title=$("#add p span");
	var btn=$("#add a span");
	if(d){
		title.hide();
		btn.html(" 添 加 分 销 商 ");
	}
	else{
		title.show();
		btn.html(" 创 建 分 类 ");
	}
	for(var i=0;i<id.length;i++){
		var pid=id[i];
		var info=n[pid].split("-");
		$('<tr><td><input type="checkbox" value="'+pid+'"/></td><td>'+info[0]+'</td><td>'+info[1]+'</td></tr>').insertAfter(tr.eq(0));
	}
}
function addC(){
	var id=[];
	var title=$("#add span input:text").val();
	$("#add table tbody tr td input:checkbox").each(function(i,e){
		if(e.checked){
			id.push(e.value);
			$("#"+e.value).remove();
		}
	});
	if(!title){alert('请填写分类名称');return;}
	var cid=$.ajax({url:"call/release.php",data:{type:"add",id:id.toString(),cid:dtype,title:title},async:false}).responseText;
	if(dtype){
	}
	else{
		$("#pid").after('<table class="C" id="C'+cid+'" border="1px"><tr><th><span onclick="_open(this)" class="open">-</span>'+title+'<a href="javascript:void(0);" class="addFx" onclick="add('+cid+')">添加分销商>></a></th><td class="C_r" rowspan="2">'+$('#mod').html()+'</td></tr><tr><td class="list"></td></tr></table>');
	}
	$("#C"+cid).removeClass('hidden');
	$("#C"+cid+" tbody tr th span").html('-');
	for(var i=0;i<id.length;i++){
		var info=n[id[i]].split("-");
		$("#C"+cid+" tbody tr td.list").append('<span id="'+id[i]+'">'+info[1]+'（ID:'+info[0]+'）</span>');
	}
	$('#add').hide();
	$('#mask').hide();
}
function soh(th){
	$(th).parent().parent().children().each(function(i,e){
		if(i!=0){
			$(e).toggle();
		}
	})
	th.innerHTML=th.innerHTML=="+"?"-":"+";
}
function _open(o){
	o.innerHTML=o.innerHTML=="+"?"-":"+";
	$(o).parent().parent().parent().parent().toggleClass('hidden');
}
</script>
<div class="wrap">
	<table class="info" border="1">
		<tr>
			<th style="width:25%;">产品名称</th>
		<?	foreach($pid as $v){?>
			<th><?=$p_name[$v]?>(供货价)</td>
		<?	}?>
		</tr>
		<tr>
			<th><?=$ltitle?></th>
		<?	foreach($pid as $v){?>
			<td><?=$fp[$v]?> 元</td>
		<?	}?>
		</tr>
	</table>
	<iframe name="ifr" style="display:none;"></iframe>
  <form action="release_dt.php" target="ifr">
	<button type="button" onclick="add()">创建分类</button>
	<font color="red">您可以将您的分销商分类以方便价格配置。</font>
	<input type="hidden" name="pid" id="pid" value="<?=$_REQUEST["pid"]?>"/>
	<?	foreach($class as $k=>$v){?>
	<table class="C hidden" border="1px" id="C<?=$k?>">
		<tr>
			<th>
				<span onclick="_open(this)" class="open">+</span><?=$cN[$k]?><a href="javascript:void(0);" class="addFx" onclick="add(<?=$k?>)">添加分销商>></a>
			</th>
			<td class="C_r" rowspan="2">
			<?	foreach($pid as $p){?>
				<span><?=$p_name[$p]?>：<input type="text" class="pri_inp" name="C<?=$p?>[<?=$k?>]" id="" /></span>
			<?	}?>
			</td>
		</tr>
		<tr>
			<td class="list">
		<?	foreach($v as $f){?>
				<span id="<?=$f['id']?>"><?=$f['dname']?>（ID:<?=$f['account']?>）</span>
		<?	}?>
			</td>
		</tr>
	</table>
	<?	}?>
	<?if($son){?>
	<table border="1" >
		<tr>
			<th>分销商账号</th>
			<th>分销商名称</th>
			<th>结算价</th>
		</tr>
	<?	foreach($son as $s){?>
		<tr id="<?=$s['id']?>">
			<td><?=$s['account']?></td>
			<td><?=$s['dname']?></td>
			<td>
			<?	foreach($pid as $p){?>
				<span><?=$p_name[$p]?>：<input class="pri_inp" type="text" name="p<?=$p?>[<?=$s['id']?>]"/></span>
			<?	}?>
			</td>
		</tr>
	<?	}?>
	</table>
	<?}?>
	<button type="submit" class="ok">完成</button>
  </form>
	<div id="add" style="display:none;">
		
	  <form action="" target="ifr">
		<p><span><b>分类名称：</b><input type="text" name="" class="ctitle"/></span><button type="button" class="close" onclick="$('#add').hide();$('#mask').hide();">X</button></p>
		<table border="1" >
			<tr>
				<th></th>
				<th>分销商账号</th>
				<th>分销商名称</th>
			</tr>
		</table>
		<a class="addcp btn" onclick="addC()" href="javascript:void(0);"><span> 添 加 分 销 商 </span></a>
	  </form>
	</div>
	<div id="mod">
	<?	foreach($pid as $p){?>
		<span><?=$p_name[$p]?>：<input type="text" class="pri_inp" name="C<?=$p?>[<?=$k?>]"/></span>
	<?	}?>
	</div>
</div>
<?include("common/footer.html");?>